package zhongbo.javaweb.instagram.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import zhongbo.javaweb.instagram.dto.JsonRespDto;
import zhongbo.javaweb.instagram.dto.NextIdDto;
import zhongbo.javaweb.instagram.service.UserIdService;

/**
 * 说明：
 *
 * @author zhongboWork
 * @version 1.0
 * @since 2022-01-06 16:09
 */
@Controller
@RequestMapping("Ins/user")
@Api(value = "InsUserId相关接口", tags = {"InsUserId相关接口"})
@Slf4j
public class InsIdController {

    @Autowired
    private UserIdService userIdService;

    @ResponseBody
    @RequestMapping(value = "/count", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询记录总数接口")
    public JsonRespDto<Integer> count() {
        return new JsonRespDto<Integer>().setData(userIdService.total()).makeSuccess();
    }

    @ResponseBody
    @RequestMapping(value = "/current", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询当前进度")
    public JsonRespDto<Integer> current() {
        return new JsonRespDto<Integer>().setData(userIdService.current()).makeSuccess();
    }

    @ResponseBody
    @RequestMapping(value = "/next", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询下条记录接口")
    public JsonRespDto<NextIdDto> next() {
        return new JsonRespDto<NextIdDto>().setData(userIdService.next()).makeSuccess();
    }

    @ResponseBody
    @RequestMapping(value = "/move", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "移动当前索引接口")
    public JsonRespDto<Integer> move(int i) {
        userIdService.move(i);
        return new JsonRespDto<Integer>().makeSuccess();
    }

    @ResponseBody
    @RequestMapping(value = "/reset", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "重置索引起点接口")
    public JsonRespDto<Integer> reset() {
        userIdService.reset();
        return new JsonRespDto<Integer>().makeSuccess();
    }
}
